<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
    <meta name="apple-touch-fullscreen" content="yes" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="x5-fullscreen" content="true" />
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />

    <!-- 标题及搜索关键字 -->
    <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
    <meta
      name="description"
      content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS"
    />

    <link rel="shortcut icon" type="image/x-icon" href="http://mars3d.cn/favicon.ico" />
    <title>油气站标注|Mars3D|三维地图| 火星科技|合肥火星科技|合肥火星科技有限公司</title>

    <script
      type="text/javascript"
      src="../lib/include-lib.js"
      libpath="../lib/"
      include="jquery,font-awesome,bootstrap,bootstrap-checkbox,layer,haoutil,turf,mars3d"
    ></script>

    <link href="css/style.css" rel="stylesheet" />
    <link href="css/divGraphic.css" rel="stylesheet" />
  </head>

  <body class="dark">
    <!--加载前进行操作提示，优化用户体验-->
    <div id="mask" class="signmask" onclick="removeMask()"></div>

    <div id="mars3dContainer" class="mars3d-container"></div>

    <div class="infoview initDivGraphic">
      效果：
      <div class="btn-group" role="group">
        <input id="btnDivgraphicYellow" type="button" class="btn btn-primary active" value="效果一" />
        <input id="btnDivgraphicBule" type="button" class="btn btn-primary" value="效果二" />
        <input id="btnDivgraphicWhite" type="button" class="btn btn-primary" value="效果三" />
      </div>
    </div>

    <script src="./js/common.js"></script>

    <script type="text/javascript">
      "use script"; //开发环境建议开启严格模式

      var map;
      var graphicLayer;

      var arrData = [
        { name: "油罐一", position: [117.09521, 31.814404, 47.3] },
        { name: "油罐二", position: [117.095206, 31.814878, 47.3] },
        { name: "油罐三", position: [117.094653, 31.814428, 47.3] },
        { name: "发电机", position: [117.093428, 31.816959, 31.8] },
        { name: "指挥室", position: [117.093953, 31.814397, 36] },
        { name: "加热罐", position: [117.09385, 31.815837, 36.9] },
        { name: "冷却室", position: [117.094662, 31.816403, 32.9] },
      ];

      function initMap(options) {
        //合并属性参数，可覆盖config.json中的对应配置
        var mapOptions = mars3d.Util.merge(options, {
          scene: {
            center: { lat: 31.81226, lng: 117.096703, alt: 231, heading: 329, pitch: -28 },
          },
        });

        //创建三维地球场景
        map = new mars3d.Map("mars3dContainer", mapOptions);

        // 加载油田联合站模型
        let tiles3dLayer = new mars3d.layer.TilesetLayer({
          pid: 2020,
          type: "3dtiles",
          name: "油田联合站",
          url: "//data.mars3d.cn/3dtiles/max-ytlhz/tileset.json",
          position: { lng: 117.094224, lat: 31.815859, alt: 26.4 },
          rotation: { z: 116.2 },
          maximumScreenSpaceError: 1,
          center: { lat: 32.407076, lng: 117.459703, alt: 3361, heading: 358, pitch: -51 },
        });
        map.addLayer(tiles3dLayer);

        //创建DIV数据图层
        graphicLayer = new mars3d.layer.DivLayer();
        map.addLayer(graphicLayer);

        // 初始加载
        divGraphicYellow();

        // 按钮切换效果
        $("#btnDivgraphicYellow").click(function () {
          $(".active").removeClass("active");
          $(this).addClass("active");

          divGraphicYellow();
        });
        $("#btnDivgraphicBule").click(function () {
          $(".active").removeClass("active");
          $(this).addClass("active");

          divGraphicBule();
        });
        $("#btnDivgraphicWhite").click(function () {
          $(".active").removeClass("active");
          $(this).addClass("active");

          divGraphicWhite();
        });

        // 效果一
        function divGraphicYellow() {
          graphicLayer.clear();

          for (let i = 0; i < arrData.length; i++) {
            let item = arrData[i];

            var divGraphic = new mars3d.graphic.DivGraphic({
              position: item.position,
              style: {
                html: `<div class="marsBlackPanel  animation-spaceInDown">
                        <div class="marsBlackPanel-text" style="">
                          ${item.name} <span class="temperature"></span> ℃
                        </div>
                      </div>`,
                horizontalOrigin: Cesium.HorizontalOrigin.LEFT,
                verticalOrigin: Cesium.VerticalOrigin.CENTER,
              },
              attr: {
                index: i + 1,
                duNum: 0,
              },
            });
            graphicLayer.addGraphic(divGraphic);

            //刷新局部DOM,不影响popup面板的其他控件操作
            divGraphic.on(mars3d.EventType.postRender, function (event) {
              let container = event.container; //popup对应的DOM
              let graphic = event.target;

              let oldVal = graphic.attr.duNum;
              let newVal = Number(new Date().format("ss")) + graphic.attr.index;
              if (oldVal !== newVal) {
                graphic.attr.duNum = newVal;
                let temperatureDom = container.querySelector(".temperature");
                if (temperatureDom) {
                  temperatureDom.innerHTML = newVal;
                }
              }
            });
          }
        }

        // 效果二
        function divGraphicBule() {
          graphicLayer.clear();

          for (let i = 0; i < arrData.length; i++) {
            let item = arrData[i];

            var divGraphic = new mars3d.graphic.DivGraphic({
              position: item.position,
              style: {
                html: `<div class="marsBlueGradientPnl">
                    <div>${item.name}</div>
                </div>`,
                offsetY: -60,
                horizontalOrigin: Cesium.HorizontalOrigin.CENTER,
                verticalOrigin: Cesium.VerticalOrigin.BTOOM,
              },
            });
            graphicLayer.addGraphic(divGraphic);
          }
        }

        // 效果三
        function divGraphicWhite() {
          graphicLayer.clear();

          for (let i = 0; i < arrData.length; i++) {
            let item = arrData[i];

            var divGraphic = new mars3d.graphic.DivUpLabel({
              position: item.position,
              style: {
                text: item.name,
                color: "#fff",
                font_size: 16,
                font_family: "微软雅黑",
                lineHeight: 50,
                circleSize: 8,
                distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 100000), //按视距距离显示
              },
            });
            graphicLayer.addGraphic(divGraphic);
          }
        }
      }
    </script>
  </body>
</html>
